route.js 727 B

123456789101112131415161718192021222324252627
  1. // app/api/branches/[branch]/[year]/[month]/days/route.js
  2. import { NextResponse } from "next/server";
  3. import { listDays } from "@/lib/storage";
  4. export function GET(request, { params }) {
  5. const { branch, year, month } = params;
  6. if (!branch || !year || !month) {
  7. return NextResponse.json(
  8. { error: "branch, year oder month fehlt" },
  9. { status: 400 }
  10. );
  11. }
  12. return listDays(branch, month.length === 4 ? branch : year, month)
  13. .then((days) => NextResponse.json({ branch, year, month, days }))
  14. .catch((error) => {
  15. console.error(
  16. "[api/branches/[branch]/[year]/[month]/days] Fehler:",
  17. error
  18. );
  19. return NextResponse.json(
  20. { error: "Fehler beim Lesen der Tage" },
  21. { status: 500 }
  22. );
  23. });
  24. }